package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.User;
import service.IUserService;
import serviceimpl.UserServiceImpl;

/**
 * Servlet implementation class UpdateUserById
 */
@WebServlet("/UpdateUserById")
public class UpdateUserById extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	   int id=Integer.parseInt(request.getParameter("Id"));
	   String name = request.getParameter("uname");
		String password = request.getParameter("upwd");
		User user=new User();
		user.setId(id);
		user.setUsername(name);
		user.setPassword(password);
//	   UserService us=new UserService();
		IUserService us=new UserServiceImpl();
	   boolean flag=us.updateUserById(id,user);
	   if(flag) {
		     request.setAttribute("error", "updateok");
		  	 
	   }else {
		   request.setAttribute("error", "updateno");
	   }
	   request.getRequestDispatcher("QueryUserByPageNowServlet").forward(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
